package cn.jdy.anquan.admin;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.anquan.entity.SiteBook;
import cn.jdy.anquan.service.SiteBookService;
import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;

/**
 * 留言列表
 * Created by hk_ti on 2015/6/14.
 */
@Controller
@RequestMapping("/siteBook")
public class SiteBookCtrl extends BaseCtrl {

    @Autowired
    private SiteBookService siteBookService;

    @RequestMapping("/list")
    public ModelAndView list() {
        return new ModelAndView("/siteBook/siteBookList.jsp");
    }

    @RequestMapping("/delete/{id}")
    public ModelAndView delete(@PathVariable Long id) {
        siteBookService.delete(id);
        return list();
    }

    /**
     *
     * @param siteBook
     * @param fromDate
     * @param toDate
     * @return
     */
    @RequestMapping("/queryByPage")
    @ResponseBody
    public Map<String, Object> queryByPage(SiteBook siteBook, String fromDate, String toDate) {
        return siteBookService.queryByPage(siteBook, fromDate, toDate);
    }
    
	@RequestMapping("/oper")
	@ResponseBody
	public Map<String, Object> oper(String id, int type, String value) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		try {
			switch(type) {
			case 1:
				siteBookService.update(Long.valueOf(id), "status", "0");//审核通过
				break;
			case 2:
				siteBookService.update(Long.valueOf(id), "status", "1");
				break;
			default:
				break;
		}
			jsonMap.put("statusCode", 200);
		} catch(Exception e) {
			jsonMap.put("statusCode", 500);
			BaseLog.e(getClass(), "留言更新异常！", e);
		}
		return jsonMap;
	}
}
